package br.com.fiap.view;

import br.com.fiap.model.Sac;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(urlPatterns = "/gerarRespostaPesquisa")
public class RespostaPesquisa extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        StringBuilder sb = new StringBuilder();
        sb.append("<!DOCTYPE html>");
        sb.append("<html>");
        sb.append("<head>");
        sb.append("<title>SAC - Pesquisar</title>");
        sb.append("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>");
        sb.append("<link type='text/css' href='css/common.css' rel='stylesheet'/>");
        sb.append("</head>");
        sb.append("<body>");
        sb.append("<div id='formulario'>");
        sb.append("<div>");
        sb.append("<h1>SAC - Pesquisar</h1>");
        sb.append("</div>");
        sb.append("<fieldset>");

        List<Sac> sacList = (List<Sac>) req.getAttribute("sacList");
        for (Sac s : sacList) {
            sb.append("<p><label>Nome: </label>").append(s.getNome()).append("</p>");
            sb.append("<p><label>Data: </label>").append(s.getDtCriacao()).append("</p>");
            sb.append("<p><label>Produto: </label>").append(s.getProduto()).append("</p>");
            sb.append("<br/>");
            sb.append("<br/>");
        }

        sb.append("<div id='voltarMenu'>");
        sb.append("<a href='index.html'>Voltar Menu</a>");
        sb.append("</div>");
        sb.append("</fieldset>");
        sb.append("</div>");
        sb.append("</body>");
        sb.append("</html>");

        PrintWriter writer = resp.getWriter();
        writer.println(sb.toString());
    }
}
